<cfparam name="url.action" default="">
<cfif Session.id EQ 0>
	<cfif IsDefined('form.name') AND IsDefined('form.password')>
		<cfquery name="user" datasource="#Request.DS#">
			SELECT * FROM `cfp_users` WHERE `name` like <cfqueryparam value="#form.name#" cfsqltype="cf_sql_varchar">
		</cfquery>
		<cfif user.password EQ Hash(form.password, "MD5") >
			<cfset Session.id = user.id >
			<cflocation url="entries/entries.cfm">
		<cfelse>
			<strong>Falsche Zugangsdaten!</strong>
		</cfif>
	</cfif>
	<cf_template i="1">
		<form method="post" action="index.cfm">
			<fieldset>
				<legend>cfProtocol Login</legend>
				<label for="name">Username:</label>
					<input type="text" name="name" id="name">
				<label for="password">Passwort:</label>
					<input type="password" name="password" id="passwort">
				<p align="center"><input type="submit" value="Login"></p>
			</fieldset>
		</form>
	</cf_template>
<cfelse>
	<cfif url.action EQ 'logout' >
		<cfset Session.id = 0 >
		<cflocation url="index.cfm">
	<cfelse>
		<cflocation url="entries/entries.cfm">
	</cfif>
</cfif>